<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Documents extends Model
{
    protected $table = 'documents';
    protected $primaryKey = 'id';
    
    public static function getDocumentsTitle()
    {
        return self::select("id","title","documents_id","product_id","authority","icon")->where("disable",1)->orderBy("sort","DESC")->get();
    }

    public static function getDocumentsDetial($id)
    {
        return self::where("id",$id)->first();
    }

    public static function helpersAdminLists()
    {
        return self::get();
    }

    public static function helpersLists()
    {
        return self::select("id","title","product_id","documents_id","created_at")->where("disable",1)->get();
    }

    public static function helpersDetial($id)
    {
        return self::where("id",$id)->first();
    }

    public static function helpersUpdate($id,$title,$documents_id,$product_id,$disable,$msg)
    {
        return self::where("id",$id)->update(["title"=>$title,"documents_id"=>$documents_id,"product_id"=>$product_id,"disable"=>$disable,"msg"=>$msg]);
    }

    public static function helpersInsert($title,$documents_id,$product_id,$disable,$msg)
    {
        return self::insert(["title"=>$title,"documents_id"=>$documents_id,"product_id"=>$product_id,"disable"=>$disable,"msg"=>$msg,"created_at"=>time()]);
    }

}